package com.djf.eg.vo;

import java.util.ArrayList;
import java.util.List;

import com.alibaba.fastjson.JSONArray;
import com.djf.eg.entity.SysPermission;
import com.djf.eg.entity.SysRole;
import com.djf.eg.entity.UserInfo;

public class UserInfoVo extends UserInfo{

	/**
	 * 
	 */
	private static final long serialVersionUID = -474864253553392221L;
	
	private JSONArray menus;
	private JSONArray permissions;
	public JSONArray getMenus() {
		return menus;
	}
	public void setMenus() {
		List<Object> menuCodeList = new ArrayList<Object>();
//		JSONArray menuItem = new JSONArray();
		List<SysRole> roles = this.getRoles();
		
		for (SysRole role : roles) {
			List<SysPermission> permissions = role.getPermissions();
			for (SysPermission permission : permissions) {
				if (!menuCodeList.contains(permission.getMenuCode())) {
					menuCodeList.add(permission.getMenuCode());
				}
			}
		}
//		if (role != null) {
//			List<SysPermission> permissions = role.getPermissions();
//			for (SysPermission permission : permissions) {
//				if (!menuCodeList.contains(permission.getMenuCode())) {
//					menuCodeList.add(permission.getMenuCode());
//				}
//			}
//		}
		this.menus = new JSONArray(menuCodeList);
//		this.menus = menus;
	}
	public JSONArray getPermissions() {
		return permissions;
	}
	public void setPermissions() {
		List<Object> resultList = new ArrayList<Object>();
//		JSONArray menuItem = new JSONArray();
		List<SysRole> roles = this.getRoles();
		
		for (SysRole role : roles) {
			List<SysPermission> permissionList = role.getPermissions();
			for (SysPermission permission : permissionList) {
				resultList.add(permission.getPermissionCode());
			}
		}
		
//		if (role != null) {
//			List<SysPermission> permissionList = role.getPermissions();
//			for (SysPermission permission : permissionList) {
//				resultList.add(permission.getPermissionCode());
//			}
//		}
		this.permissions = new JSONArray(resultList);
//		this.permissions = permissions;
	}
	
	
}
